﻿//-------------------------------------------------------------------
//	Copyright (c) 2010-2014  Zhirnov Andrey
//	This file is part of the "UX Standard Lib" project.
//	See copyright notice in "UX_STL_Ext.h".
//-------------------------------------------------------------------

#ifndef _UXS_CL_QUEUE_H
#define _UXS_CL_QUEUE_H

#pragma once

#include "CLDevice.h"
#include "CLEvent.h"

namespace UX_STL
{
namespace CLShell
{


	//
	// CL Queue
	//

	class UX_EXPORT CLQueue : public CLBaseObject
	{
	protected:
		cl_command_queue	_pID;
		
	protected:
		virtual void _RetainRef()	const;
		virtual void _ReleaseRef()	const;
		virtual uint _GetRefCount()	const;
		virtual void _Destroy();

	public:
		CLQueue();
		~CLQueue();

		bool Create(cl_queue_property::type eFlags = cl_queue_property::NONE);
		virtual void Destroy();

		bool Flush() const;
		bool Finish() const;
		bool EnqueueBarrier() const;
		bool EnqueueWait(const clevent_uni_array &aEvents) const;
		bool EnqueueMarker(CLEvent *&pEvent) const;

		//bool EnqueueNativeKernel(void (*pUserFunc)(void *), void *pArgs, usize uArgsSize, const mem_obj_array_t &aMemList,
		//				const clevent_uni_array &aEvents = clevent_uni_array(), CLEvent **pEvent = null) const;
		
		bool  EnqueueTask(CLKernel *pKernel, const clevent_uni_array &aEvents = clevent_uni_array(), CLEvent **pEvent = null) const;
		
		bool  EnqueueNDRange(CLKernel *pKernel, const svec3 &vGlobalWorkOffsets,
							 const svec3 &vGlobalWorkSizes, const svec3 &vLocalWorkSizes,
							 const clevent_uni_array &aEvents = clevent_uni_array(), CLEvent **pEvent = null) const;

		bool EnqueueAcquireGLObjects(const clmem_uni_array &aMemList,
						const clevent_uni_array &aEvents = clevent_uni_array(), CLEvent **pEvent = null) const;

		bool EnqueueReleaseGLObjects(const clmem_uni_array &aMemList,
						const clevent_uni_array &aEvents = clevent_uni_array(), CLEvent **pEvent = null) const;

		cl_command_queue	Id()	const	{ return _pID; }
	};

//-------------------------------------------------------------------

}	// CLShell
}	// UX_STL

#endif	// _UXS_CL_QUEUE_H